import OrderSearch from '../../components/Order/OrderSearch';
import OrderList from '../../components/Order/OrderList';
import OrderModal from '../../components/Order/OrderModal';
import * as PropTypes from "react";
import {connect} from 'dva';

function Order({location, dispatch, order}) {
  const {
    modalVisible, modalType, item, btnLoading, modalLoading,
    total, pageNumber, pageSize, loading, list,
    typeVisible, typeBtnLoading,
  }= order;
  const OrderListProps = {
    total, pageNumber, pageSize, loading, list,
    /**
     * 导出Excel
     */
    handleExport(){

    },
    onPageChange(page) {
      dispatch({
        type: 'order/query',
        payload: {
          pageNumber: page,
          pageSize,
        },
      });
    },
    onShowSizeChange(current, pageSize) {
      dispatch({
        type: 'order/query',
        payload: {
          pageNumber: current,
          pageSize,
        },
      });
    },
    onAdd() {
      dispatch({
        type: 'order/showModal',
      });
    },
    onDeleteItem(id) {
      dispatch({
        type: 'order/delete',
        payload: {
          id,
          pageNumber,
          pageSize,
        },
      });
    },
    onEditItem(id) {
      dispatch({
        type: 'order/detail',
        payload: {
          modalType: 'update',
          id,
        },
      });
    },
  };
  const OrderModalProps = {
    modalVisible,
    onCancel(){
      dispatch({
        type: 'order/hideModal'
      });
    }
  };

  const OrderSearchProps = {
    onSearch(data){
      dispatch({
        type: 'order/searchInCondition',
        payload: {
          data
        }
      });
    }
  };

  return (
    <div className="container" style={{padding:20}}>
      <OrderSearch{...OrderSearchProps} />
      <OrderList {...OrderListProps}/>
      <OrderModal {...OrderModalProps}/>
    </div>
  );
}

// Order.propTypes = {
//   // location: PropTypes.object,
//   // dispatch: PropTypes.func,
//   order: PropTypes.object,
// };

export default connect(({order}) => ({order}))(Order);
